package org.example.entity;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author TonySong
 * @date 2025/7/28 0028
 * @time 16:36
 */
public class FreeTicket extends Ticket implements Serializable {
    private String customerName;

    public FreeTicket(Movie movie, String customerName) {
        super(movie);
        this.customerName = customerName;
    }

    @Override
    public int calc() {
        return 0;
    }

    @Override
    public void printTicket() {
        String filename = "free_ticket_" + System.currentTimeMillis() + ".txt";
        try (FileWriter writer = new FileWriter(filename)) {
            writer.write("========== 赠票 ==========\n");
            writer.write("电影名称: " + getMovie().getName() + "\n");
            writer.write("放映时间: " + getMovie().getPlayTime() + "\n");
            writer.write("座位号: " + getSeat() + "\n");
            writer.write("原价: ¥" + getMovie().getPrice() + "\n");
            writer.write("实际票价: ¥" + calc() + "\n");
            writer.write("票种: 赠票\n");
            writer.write("客户姓名: " + customerName + "\n");
            writer.write("购票时间: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "\n");
            writer.write("============================\n");
            System.out.println("学生电影票已打印到文件: " + filename);
        } catch (IOException e) {
            System.err.println("打印赠票电影票时出错: " + e.getMessage());
        }
    }

    @Override
    public void showTicket(){
        System.out.println("========== 电影票 ==========");
        System.out.println("电影名称: " + getMovie().getName());
        System.out.println("放映时间: " + getMovie().getPlayTime());
        System.out.println("座位号: " + getSeat());
        System.out.println("票价: ¥" + calc());
        System.out.println("客户姓名: "+customerName);
        System.out.println("购票时间: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        System.out.println("========================");
    }
}
